#!/bin/bash
#    
# chkconfig: 2345 85 85    
# description: redis is a web server    
# processname: redis  
NAME=redis
BIN=/usr/local/bin/redis-server
CONFIGFILE=/etc/redis.conf
LOGFILE=/root/golsee/tmp/$NAME.log
SCRIPTNAME=/etc/init.d/$NAME
start(){
	echo -n "Starting $NAME... "
	PID=`pidof redis-server`
	if [[ -n $PID ]]; then
		echo "$NAME is running."
	else
		$BIN $CONFIGFILE
		if [ $? != 0 ] ; then
			echo " failed"
		else
			echo " done"
		fi
	fi
}
stop(){
	echo -n "Stoping $NAME... "
	PID=`pidof redis-server`
	if [[ -z $PID ]]; then
		echo "$NAME is not running."
	else
		killall -9 $BIN
		if [ $? != 0 ] ; then
			echo " failed."
		else
			echo " done"
		fi
	fi
}
status(){
	PID=`pidof redis-server`
	if [[ -n $PID ]]; then
		echo "$NAME (pid $PID) is running..."
	else
		echo "$NAME is stopped"
		exit 0
	fi
}
restart(){
	stop
	sleep 1
	start
}
case "$1" in
	start)
		start
	;;
	stop)
		stop
	;;
	status)
		status
	;;
	restart)
		restart
	;;
	*)
		echo "Usage: $SCRIPTNAME {start|stop|restart|status}"
		exit 1
	;;
esac
